/****************************************
*  This file created using "Writer B"   *
*      a program written by CTonk       *
*          ctonk87@hotmail.com          *
*     [timestamp 02/20/06  12:51:45]    *
****************************************/

// Area.cpp

#ifndef CPP_AREA
#define CPP_AREA

#include "Area.h"


// Constructors...
Area::Area()
{
	_number = 0;
	_firstv = 0;
	_lastv = 0;
	_size = 0;
	_keyword = new char[20];
	for ( int x=0; x < 20; x++ )
		_keyword[x] = '\0';
	_file = new char[55];
	for ( int x=0; x < 55; x++ )
		_file[x] = '\0';
	_name = new char[40];
	for ( int x=0; x < 40; x++ )
		_name[x] = '\0';
}

Area::Area( Area& it )
{
	_number = it._number;
	_firstv = it._firstv;
	_lastv = it._lastv;
	_size = it._size;
	for ( int x=0; x < 20; x++ )
		_keyword[x] = it._keyword[x];
	for ( int x=0; x < 55; x++ )
		_file[x] = it._file[x];
	for ( int x=0; x < 40; x++ )
		_name[x] = it._name[x];
	for ( int x=0; x < _rooms.GetSize(); x++ )
		*(_rooms[x]) = *(it.GetRoom( x ));
	for ( int x=0; x < _objects.GetSize(); x++ )
		*(_objects[x]) = *(it.GetObject( x ));
}

Area::~Area()
{
	delete[] _keyword;
	delete[] _file;
	delete[] _name;
}

// Operators...
Area& Area::operator = ( Area& it )
{
	_number = it._number;
	_firstv = it._firstv;
	_lastv = it._lastv;
	_size = it._size;
	for ( int x=0; x < 20; x++ )
		_keyword[x] = it._keyword[x];
	for ( int x=0; x < 55; x++ )
		_file[x] = it._file[x];
	for ( int x=0; x < 40; x++ )
		_name[x] = it._name[x];
	for ( int x=0; x < _rooms.GetSize(); x++ )
		*(_rooms[x]) = *(it.GetRoom( x ));
	for ( int x=0; x < _objects.GetSize(); x++ )
		*(_objects[x]) = *(it.GetObject( x ));
	return *this;
}

Room* Area::operator [] ( int number )
{
	return this->_rooms[ number ];
}

// Public accessor methods...
int Area::GetNumber()
{
	return _number;
}

void Area::SetNumber( int number )
{
	_number = number;
}

int Area::GetFirstv()
{
	return _firstv;
}

void Area::SetFirstv( int firstv )
{
	_firstv = firstv;
}

int Area::GetLastv()
{
	return _lastv;
}

void Area::SetLastv( int lastv )
{
	_lastv = lastv;
}

int Area::GetSize()
{
	return _size;
}

void Area::SetSize( int size )
{
	_size = size;
}

char* Area::GetKeyword( void )
{
	return _keyword;
}

char Area::GetKeyword( int x )
{
	return _keyword[x];
}

void Area::SetKeyword( char* val )
{
	strcpy( _keyword, val );
	return;
}

void Area::SetKeyword( const char* val )
{
	strcpy( _keyword, val );
	return;
}

void Area::SetKeyword( int x, char val )
{
	_keyword[x] = val;
}

char* Area::GetFile( void )
{
	return _file;
}

char Area::GetFile( int x )
{
	return _file[x];
}

void Area::SetFile( char* val )
{
	strcpy( _file, val );
	return;
}

void Area::SetFile( const char* val )
{
	strcpy( _file, val );
	return;
}

void Area::SetFile( int x, char val )
{
	_file[x] = val;
}

char* Area::GetName( void )
{
	return _name;
}

char Area::GetName( int x )
{
	return _name[x];
}

void Area::SetName( char* val )
{
	strcpy( _name, val );
	return;
}

void Area::SetName( const char* val )
{
	strcpy( _name, val );
	return;
}

void Area::SetName( int x, char val )
{
	_name[x] = val;
}

Magiclist< Room* >& Area::GetRooms()
{
	return _rooms;
}

void Area::SetRooms( Magiclist< Room* >& rooms )
{
	_rooms = rooms;
	return;
}

Room* Area::GetRoom( int number )
{
	return _rooms[ number ];
}

Room* Area::SetRoom( int number, Room& room )
{
	return ( _rooms[ number ] = &room );
}

Magiclist< Object* >& Area::GetObjects()
{
	return _objects;
}

void Area::SetObjects( Magiclist< Object* >& objects )
{
	_objects = objects;
	return;
}

Object* Area::GetObject( int number )
{
	return _objects[ number ];
}

Object* Area::SetObject( int number, Object& object )
{
	return ( _objects[ number ] = &object );
}



// Other methods...
void Area::Display( std::ostream& out ) {
	out << "-Area-";
	out << "\nNumber: " << _number;
	out << "\nFirstv: " << _firstv;
	out << "\nLastv: " << _lastv;
	out << "\nSize: " << _size;
	out << "\nKeyword: " << _keyword;
	out << "\nFile: " << _file;
	out << "\nName: " << _name;
	return;
}

void Area::Display( std::string& out ) {
	out << "-Area-";
	out << "\nNumber: " << _number;
	out << "\nFirstv: " << _firstv;
	out << "\nLastv: " << _lastv;
	out << "\nSize: " << _size;
	out << "\nKeyword: " << _keyword;
	out << "\nFile: " << _file;
	out << "\nName: " << _name;
	return;
}

void Area::Save( std::ofstream& save ) {
	save << _number << ' ' << _size << ' ' << _firstv << ' '
		 << _lastv << ' ' << _keyword << '\n';
	save << _name << '\n';

	for ( int x=0; x < _rooms.GetSize(); x++ ) {
		_rooms[x]->Save( save );
	}
	/*for ( int x=0; x < _objects.GetSize(); x++ ) {
		_objects[x]->Save( save );
	}*/

	return;
}

void Area::Load( std::ifstream& load ) {
	char* temp = new char[500];
	Room* room = 0;
	Object* obj = 0;

	load >> _number >> _size >> _firstv >> _lastv >> _keyword;
	load.get(); load.getline( temp, 500 ); this->SetName( temp );

	while ( load.peek() != EOF ) {
		load.getline( temp, 500 );
		if ( same( temp, "**ROOM" ) ) {
			room = this->GetRooms().Add() = new Room;
			room->Load( load );
			continue;
		}
		if ( same( temp, "**OBJECT" ) ) {
			obj = this->GetObjects().Add() = new Object;
			obj->Load( load );
			this->GetRoom( obj->GetVnum() )->Add( obj );
			continue;
		}
		if ( same( temp, "**MOB" ) ) {
			std::cout << "Wow! A Mob!!!!!!!!!\n";
			continue;
		}
		if ( same( temp, "**RESET" ) ) {
			std::cout << "Holy cow! A reset!!\n";
			continue;
		}
	}

	return;
}



#endif // #ifndef CPP_AREA
